<template>
  <div :class="['left-box', isHidden ? 'hidden-icon' : '']">
    <div class="left-content">
      <div class="fold-icon" @click="closeLeftBox">
        <el-icon>
          <DArrowRight :class="{ 'hidden-icon': isHidden }" />
        </el-icon>
      </div>
      <div class="left-title">
        <img src="@/assets/images/home/pic_img.png" />
        <span>模型概览</span>
      </div>
      <div class="model-intro">
        <div class="intro-item" :key="index" v-for="(item, index) in introArr">
          <img src="@/assets/images/home/u11.png" />
          <div class="panal">
            <div class="word">{{ item.word }}</div>
            <div class="num">{{ item.number }}</div>
          </div>
        </div>
      </div>
      <div class="rainfall" v-for="(item, index) in state.modelArr" :key="index">
        <div class="model-header">
          <div class="model-title">{{ item.modelTitle }}</div>
          <el-popover effect="dark" placement="right" width="300" trigger="click">
            <template #reference>
              <div class="model-more" v-if="item?.models.length > 2">更多></div>
            </template>
            <div class="model-content">
              <div v-for="(e, num) in item.models" :key="num">
                <div
                  :class="
                    state.activeClass == index && state.modelIndex == num
                      ? 'models-active'
                      : 'models'
                  "
                  @click="clickRain(index, num, e)"
                >
                  <img
                    v-if="state.activeClass == index && state.modelIndex == num"
                    src="@/assets/images/home/u229.png"
                  />
                  <img v-else src="@/assets/images/home/u19.png" />
                  <div class="model-info">
                    <el-tooltip
                      class="item"
                      effect="dark"
                      :content="e.typeName + e.version"
                      placement="top"
                    >
                      <span>{{ e.typeName }}{{ e.version }}</span>
                    </el-tooltip>
                  </div>
                </div>
              </div>
            </div>
          </el-popover>
        </div>
        <div class="model-content">
          <div v-for="(e, num) in item.models.slice(0, 3)" :key="num">
            <div
              :class="
                state.activeClass == index && state.modelIndex == num ? 'models-active' : 'models'
              "
              @click="clickRain(index, num, e)"
            >
              <img
                v-if="state.activeClass == index && state.modelIndex == num"
                src="@/assets/images/home/u229.png"
              />
              <img v-else src="@/assets/images/home/u19.png" />
              <div class="model-info">
                <el-tooltip
                  class="item"
                  effect="dark"
                  :content="e.btnName + e.version"
                  placement="top"
                >
                  <span>{{ e.btnName }}{{ e.version }}</span>
                </el-tooltip>
              </div>
            </div>
          </div>
        </div>
      </div>
      <div class="map-box">
        <mapBaseLayer @handleChangeTree="handleChangeTree" />
      </div>
    </div>
  </div>
</template>
<script setup>
import { ref, reactive, onMounted } from 'vue'
import emitter from '@/utils/bus'
import home from '@/assets/data/home.json'
import mapBaseLayer from '@/components/app-map/mapBaseLayer/index.vue'
import { intro, model, place } from '../../data'
import {
  // 查询模型列表
  getModelList
} from '@/services/modules/home'
const introArr = reactive(intro)
const modelArr = reactive([])
// const modelArr = reactive(home.modelData)
const placeArr = reactive(place)
const state = reactive({
  activeClass: 1,
  modelIndex: '',
  modelArr: []
  // model_list: []
})
const isHidden = ref(false)
const acceptModelList = () => {
  return new Promise((resolve, reject) => {
    getModelList({
      typeId: '',
      modelName: ''
    }).then((res) => {
      if (res.code === 200) {
        let arr = []
        res.data.forEach((item) => {
          arr.push({ modelTitle: item.specialName, specialId: item.specialId })
        })
        const map = new Map()
        const newArr = arr.filter((v) => !map.has(v.specialId) && map.set(v.specialId, 1))
        let array = newArr.map((child) => {
          return { ...child, models: res.data.filter((elem) => elem.specialId == child.specialId) }
        })
        array.forEach((e) => {
          e.models = e.models.map((i) => {
            return { ...i, btnName: i.typeName }
          })
        })
        state.modelArr = array

        clickRain(0, 0, state.modelArr[0].models[0])

        console.log(state.modelArr, '合同列表map')
      }
    })
  })
}
const emit = defineEmits('handleChangeLayer')
function handleChangeTree(e) {
  emit('handleChangeLayer', e)
}
const closeLeftBox = () => {
  isHidden.value = !isHidden.value
}
const clickRain = (index, num, item) => {
  console.log(item, 'ccc')
  state.activeClass = index
  state.modelIndex = num
  emitter.emit('trunB', true)
  emitter.emit('modelData', item)
  //
  emitter.emit('mapLayerHandle', item)

  // bottomFlag.value = true
}
function handleOpenModel() {
  clickRain(0, 0, state.modelArr[0].models[0])
}
defineExpose({ handleOpenModel })
onMounted(() => {
  acceptModelList()

  // 获取模型列表
})
</script>
<style lang="less" scoped>
.model-content {
  display: flex;
  margin-top: 23px;
  .models {
    width: 100px;
    cursor: pointer;
    text-align: center;
    padding-top: 5px;
    img {
      width: 40px;
      height: 40px;
    }
    .model-info {
      text-align: center;
      margin-top: 10px;
      span {
        max-width: 90px;
        font-size: var(--content-fontsize);
        color: #b5d7ff;
        display: inline-block;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        vertical-align: middle;
      }
    }
  }
  .models-active {
    width: 100px;
    cursor: pointer;
    text-align: center;
    padding-top: 5px;
    img {
      width: 40px;
      height: 40px;
      border-radius: 50%;
      border: 1px solid rgb(53, 173, 232);
    }
    .model-info {
      text-align: center;
      margin-top: 10px;
      span {
        color: #b5d7ff;
        max-width: 90px;
        font-size: var(--content-fontsize);
        display: inline-block;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        vertical-align: middle;
      }
    }
  }
}
.left-box {
  z-index: 101;
  position: absolute;
  top: 0;
  left: 0;
  width: 300px;
  height: 100%;
  background-image: url(@/assets/images/left_img.png);
  background-repeat: no-repeat;
  background-size: 100% 100%;
  border-radius: 4px !important;
  border: 1px solid #1c629e;
  background-color: rgba(0, 1, 125, 0) !important;
  transition: left 1s;
  .left-content {
    width: 100%;
    height: 100%;
    overflow-y: auto;
  }
  &.hidden-icon {
    left: -300px;
    transition: left 1s;
  }
  .fold-icon {
    width: 20px;
    height: 120px;
    line-height: 120px;
    position: absolute;
    background: #058cc7;
    top: 35%;
    left: 300px;
    display: flex;
    justify-content: center;
    align-items: center;
    border-top-right-radius: 35px;
    border-bottom-right-radius: 35px;
    transform: translateY(-50%);

    @keyframes myload {
      from {
        opacity: 0;
        -webkit-transform: rotate(180deg);
        /* Safari */
        transform: rotate(180deg);
        /* 标准语法 */
      }

      to {
        opacity: 1;
        -webkit-transform: rotate(180deg);
        /* Safari */
        transform: rotate(180deg);
        /* 标准语法 */
      }
    }

    .el-icon {
      cursor: pointer;
      position: relative;
      display: block;
      color: white;
      animation: myload 1s infinite ease-in-out;
      -webkit-animation: myload 1s infinite ease-in-out;

      svg {
        &.hidden-icon {
          // border-top-right-radius: 35px;
          // border-bottom-right-radius: 35px;
          transform: rotate(180deg);
        }
      }
    }
  }
  .left-title {
    height: 35px;
    margin: 10px 0 15px 10px;
    display: flex;
    align-items: center;
    img {
      width: 30px;
      height: 30px;
      margin-right: 15px;
    }
    span {
      font-size: var(--header-fontsize);
      color: #ffffff;
    }
  }
  .model-intro {
    height: 40px;
    display: flex;
    justify-content: space-around;
    align-items: center;
    margin-bottom: 25px;
    .intro-item {
      display: flex;
      img {
        width: 40px;
        height: 40px;
        margin-right: 10px;
      }
      .panal {
        height: 40px;
        .word {
          font-size: var(--content-fontsize);
          line-height: 20px;
          text-align: center;
          color: rgb(53, 173, 232);
        }
        .num {
          line-height: 20px;
          text-align: center;
          font-size: var(--content-fontsize);
          font-weight: bold;
          color: rgb(0, 238, 255);
        }
      }
    }
  }
  .rainfall {
    position: relative;
    border-radius: 8px;
    margin: 0 0 0 10px;
    height: calc((100% - 160px) / 5);
    background-color: transparent;
    box-sizing: border-box;
    .model-header {
      padding: 10px 0 0 15px;
      display: flex;
      justify-content: space-between;
      .model-title {
        font-size: var(--content-fontsize);
        font-weight: 500;
        color: #ffffff;
      }
      .model-more {
        margin-right: 15px;
        cursor: pointer;
        color: white;
        font-size: var(--content-fontsize);
      }
    }
  }
  .map-box {
    position: absolute;
    left: 300px;
    bottom: 30px;
  }
}
</style>
